﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;


namespace Dungeon_Dive
{
    /// <summary>
    /// Screen for displaying credits.
    /// </summary>
    public class CreditScreen : GameScreen
    {        
        SpriteBatch sb;
        SpriteFont font;

        private Log log;

        public CreditScreen(Game1 game)
            : base(game)
        {
        }

        /// <summary>
        /// Initialize Credit Screen.
        /// </summary>
        public override void Initialize()
        {
            log = (Log)parentGame.Services.GetService(typeof(Log));
            log.Write("CreditScreen.Init()");
            base.Initialize();
        }

        protected override void LoadContent()
        {
            log.Write("CreditScreen.LoadContent()");
            ContentManager contentManager = (ContentManager)parentGame.Services.GetService(typeof(ContentManager));
            sb = contentManager.SpriteBatch;            
            font = contentManager.Font;
            base.LoadContent();
        }

        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
        }

        /// <summary>
        /// Draws credits on the screen.
        /// </summary>
        /// <param name="gameTime"></param>
        public override void Draw(GameTime gameTime)
        {
            // Possibly should read text from a file?

            int blockstart = 50;
            int ls = font.LineSpacing;
            int cx = Game.Window.ClientBounds.Width / 2;

            string JTJ = "Juho Julkunen";
            string IH = "Ilkka Halila";

            sb.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.BackToFront,
                SaveStateMode.SaveState);
            sb.DrawString(font, "Design", new Vector2(cx, blockstart), Color.White);
            sb.DrawString(font, JTJ, new Vector2(cx + 100, blockstart + ls), Color.White);
            sb.DrawString(font, IH, new Vector2(cx + 100, blockstart + ls * 2), Color.White);            

            blockstart = blockstart + ls * 4;

            sb.DrawString(font, "Programming", new Vector2(cx, blockstart), Color.White);
            sb.DrawString(font, IH, new Vector2(cx + 100, blockstart + ls), Color.White);
            sb.DrawString(font, JTJ, new Vector2(cx + 100, blockstart + ls * 2), Color.White);

            blockstart = blockstart + ls * 4;

            sb.DrawString(font, "Scripting", new Vector2(cx, blockstart), Color.White);
            sb.DrawString(font, IH, new Vector2(cx + 100, blockstart + ls), Color.White);
            sb.DrawString(font, JTJ, new Vector2(cx + 100, blockstart + ls * 2), Color.White);

            blockstart = blockstart + ls * 4;

            sb.DrawString(font, "3D Models", new Vector2(cx, blockstart), Color.White);
            sb.DrawString(font, JTJ, new Vector2(cx + 100, blockstart + ls), Color.White);
            sb.DrawString(font, IH, new Vector2(cx + 100, blockstart + ls * 2), Color.White);

            blockstart = blockstart + ls * 4;

            sb.DrawString(font, "Additional Art", new Vector2(cx, blockstart), Color.White);
            sb.DrawString(font, "Niki", new Vector2(cx + 100, blockstart + ls), Color.White);            

            blockstart = blockstart + ls * 3;

            sb.DrawString(font, "Music", new Vector2(cx, blockstart), Color.White);
            sb.DrawString(font, "Wellu", new Vector2(cx + 100, blockstart + ls), Color.White);

            blockstart = blockstart + ls * 3;

            blockstart = Game.Window.ClientBounds.Height - ls;
            cx = (int)(Game.Window.ClientBounds.Width / 2 - font.MeasureString("Press Spacebar to continue.").X / 2);

            sb.DrawString(font, "Press Spacebar to continue.",
                new Vector2(cx, blockstart), Color.White);
            sb.End();

            base.Draw(gameTime);
        }
    }
}